import { Post, Put } from '../utils/request';
import { detailUrl, imageUrl, getUploadPath, deleteImageUrl } from '../utils/url';

export const getImage = (id) => {
  return Post(imageUrl, { id });
};

export const getDetail = (id) => {
  return Post(detailUrl, { id });
};

export const uploadImage = async (file, id) => {
  const preRes = await Post(getUploadPath, { id, name: file.name });
  const nextUrl = preRes.url.replace('http://', 'https://');

  return Put(nextUrl, file, {
    'Content-Type': 'multipart/form-data',
    'X-Oss-Callback': preRes.callback,
  });
};

export const deleteImage = (place) => {
  return Post(deleteImageUrl, { place });
};
